from com.mysqlconnection import mysql_connect
from  init_cs import dictfetchall
listnetworks_sql='SELECT id,NAME,broadcast_domain_type,broadcast_uri,gateway,cidr,created FROM networks WHERE NAME IS NOT NULL'
user_ips_sql='SELECT u.source_network_id,u.public_ip_address,n.`name` FROM user_ip_address AS u,networks AS n WHERE u.source_network_id=n.id  AND u.`state` ="Free" AND n.name IS NOT NULL'
netwoks_sql='SELECT * FROM networks WHERE MODE="dhcp" AND NAME !="system-network" AND specify_ip_ranges !=0'

def get_all_network_list():
    cnn=mysql_connect()
    cnn.execute(listnetworks_sql)
    return dictfetchall(cnn)

def get_all_network_name():
    cnn=mysql_connect()
    cnn.execute(netwoks_sql)
    return dictfetchall(cnn) 

def get_free_IP_Parameter():
    cnn=mysql_connect()
    cnn.execute(user_ips_sql)
    return dictfetchall(cnn)